package com.cskaoyan.controller;

import com.cskaoyan.bean.PageInfo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.UserPageInfo;
import com.cskaoyan.bean.UserPageInfo2;
import com.cskaoyan.vo.BaseRespVo;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author stone
 * @date 2022/10/07 09:20
 */
@RestController
@RequestMapping("user")
public class UserController {

    //localhost:8080/user/register1?username=songge&password=niupi&age=40
    @RequestMapping("register1")
    //public BaseRespVo register1(String username, String password, String age) {
    public BaseRespVo register1(String username, String password, int age) {
        String msg = "username:" + username + ";password:" + password + ";age:" + age;
        return BaseRespVo.ok(msg);
    }

    //localhost:8080/user/register2?username=songge&password=niupi
    @RequestMapping("register2")
    public BaseRespVo register2(String username, String password, Integer age) {
        String msg = "username:" + username + ";password:" + password + ";age:" + age;
        return BaseRespVo.ok(msg);
    }

    //localhost:8080/user/register3?username=songge&password=niupi&age=30&birthday=2022/06/21
    @RequestMapping("register3")
    public BaseRespVo register3(String username, String password, Integer age,
                                Date birthday) {
        String msg = "username:" + username + ";password:" + password + ";age:" + age;
        return BaseRespVo.ok(msg);
    }

    //localhost:8080/user/register4?username=songge&password=niupi&age=30&birthday=2022-06-21
    @RequestMapping("register4")
    public BaseRespVo register4(String username, String password, Integer age,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        String msg = "username:" + username + ";password:" + password + ";age:" + age;
        return BaseRespVo.ok(msg);
    }

    //localhost:8080/user/register5?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap&ids=1&ids=2&ids=3
    @RequestMapping("register5")
    public BaseRespVo register5(String username, String password, Integer age,
                                String[] hobbies, Integer[] ids) {
        System.out.println("hobbies = " + Arrays.asList(hobbies));
        List<Integer> integers = Arrays.asList(ids);
        System.out.println("ids = " + integers);
        return BaseRespVo.ok();
    }

    //localhost:8080/user/register6?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap&ids=1&ids=2&ids=3
    // &birthday=2022-06-21
    /*@RequestMapping("register6")
    public BaseRespVo register6(String username,String password,Integer age,
                                String[] hobbies,Integer[] ids,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        return BaseRespVo.ok();
    }*/
    // class.newInstance() user.set方法
    @RequestMapping("register6")
    public BaseRespVo register6(User user) {
        System.out.println(user);
        return BaseRespVo.ok();
    }

    @RequestMapping("query")
    public BaseRespVo query(PageInfo info, Integer age) {

        return BaseRespVo.ok();
    }

    // localhost:8080/user/query2?page=2&limit=10
    // &username=songge&password=niupi&age=30&birthday=2022-10-07&hobbies=sing&hobbies=jump&hobbies=rap
    @RequestMapping("query2")
    public BaseRespVo query2(PageInfo info, User user) {

        return BaseRespVo.ok();
    }

    // query3和query2的请求参数是一模一样的
    @RequestMapping("query3")
    public BaseRespVo query3(UserPageInfo2 userPageInfo2) {

        return BaseRespVo.ok();
    }
}
